#!/bin/bash

#Total job's
#File = subsetsum_random_4_5_without_unary.cnf
#Blocks = 1
#Threads = 1
#Number of jobs = 1
#131257841152

STATS_TYPE=none
FILE=none
BLOCKS=none
THREADS=none
JOBS=none

OUTPUT_DIRECTORY=csv_outputs

while read line
do

	if [[ "$line" =~ "Total job's" ]] || [[ "$line" =~ "Pre-processing" ]] || [[ "$line" =~ "Decision" ]] || [[ "$line" =~ "Conflict analyzing" ]] || [[ "$line" =~ "Backtracking" ]] || [[ "$line" =~ "Structures reset" ]] || [[ "$line" =~ "Creating structures" ]] || [[ "$line" =~ "Next job" ]] || [[ "$line" =~ "Add jobs to assumptions" ]] || [[ "$line" =~ "Processing results" ]]
	then
		STATS_TYPE=`echo $line | sed s/" "//g | sed s/"'"//g`
	fi

	if [[ "$line" =~ "File = " ]]
	then
		FILE=`echo $line | cut -d " " -f 3`
	fi

	if [[ "$line" =~ "Blocks = "[0-9]+ ]]
	then
		BLOCKS=`echo $line | cut -d " " -f 3`
	fi

	if [[ "$line" =~ "Threads = "[0-9]+ ]]
	then
		THREADS=`echo $line | cut -d " " -f 3`
	fi

	if [[ "$line" =~ "Number of jobs = "[0-9]+ ]]
        then
                JOBS=`echo $line | cut -d " " -f 5`
        fi

	if [[ "$line" =~ ^[0-9]+$ ]]
	then
		OUTPUT_FILE=${FILE}_b${BLOCKS}_t${THREADS}_j${JOBS}_st${STATS_TYPE}.csv
		echo $line >> ${OUTPUT_DIRECTORY}/$OUTPUT_FILE
#		echo $OUTPUT_FILE

	fi

done
